﻿var IP = 'http://192.168.30.56:8081/';
var realName = sessionStorage.getItem("realName");
var loginName = sessionStorage.getItem("loginName");
	//	
	//	private Integer id; 上传为 0 传
	//	private String loginName;登录名session
	//	private String ip; 本机IP
	//	private String system; 本地系统
	//	private String model; 模块
	//	private String operand; 操作对象
	//	private String action; 执行动作
	//	private String oldValue; 原值
	//	private String newValue;新值
var OperateSys = function() {
	var sUserAgent = navigator.userAgent;
	var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
	var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
	if (isMac) return "Mac";
	var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
	if (isUnix) return "Unix";
	var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
	if (isLinux) return "Linux";
	if (isWin) {
		var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
		if (isWin2K) return "Win2000";
		var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
		if (isWinXP) return "WinXP";
		var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
		if (isWin2003) return "Win2003";
		var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
		if (isWinVista) return "WinVista";
		var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
		if (isWin7) return "Win7";
	}
	return "other";
}
var thisOpsys = OperateSys();
var session = sessionStorage.getItem("session");

function insertopertlog(fmodel, foperand, faction, foldValue, fnewValue) {
	$.ajax({
		type: "post", // 与可以 "get"
		url: IP + "InsertUserLog?callback=?&session" + session,
		data: {
			id: 0, //上传为 0 传
			loginName: realName, //登录名session
			ip: '', //本机ip
			system: thisOpsys, //本地系统
			model: fmodel, //模块
			operand: foperand, //操作对象
			action: faction, //执行动作
			oldValue: foldValue, //原值
			newValue: fnewValue, //新值
		},
		dataType: "jsonp",
		jsonp: "callback",
		jsonpCallback: "resultHandler",
		success: function(json) {
			//console.log(json);
			if (json.result = 200) {
				console.log("更新操作日志成功！");
			} else {
				console.log("更新操作日志失败！");
			}
		}
	});
}


function DateRight(sdate, edate) {
	var a = parseInt(sdate.replace(/-/g, ''));
	var b = parseInt(edate.replace(/-/g, ''));
	if (a >= b) {
		return false;
	} else {
		return true;
	}
}

function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
	return currentdate;
}

function getThrBeforeDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month;
	if (date.getDate() <= 3) {
		month = date.getMonth();
	} else {
		month = date.getMonth() + 1;
	}
	var strDate;
	if (date.getDate() > 3) {
		strDate = date.getDate() - 3;
	} else {
		if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) {
			strDate = 28 + date.getDate();
		} else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
			strDate = 27 + date.getDate();
		} else if (date.getFullYear() % 4 == 0) {
			strDate = 26 + date.getDate();
		} else {
			strDate = 25 + date.getDate();
		}
	}
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
	return currentdate;
}
var NowDateTime = getNowFormatDate();
var ThreeDayBefore = getThrBeforeDate();


function getXlsFromTbl(inTblId, inTblContainerId, title, rownumbers) {
	try {
		var allStr = "";
		var curStr = "";
		//alert("getXlsFromTbl");  
		if (inTblId != null && inTblId != "" && inTblId != "null") {
			curStr = getTblData($('#' + inTblId), $('#' + inTblContainerId), rownumbers);
		}
		if (curStr != null) {
			allStr += curStr;
		} else {
			alert("你要导出的表不存在！");
			return;
		}
		var fileName = getExcelFileName(title);
		doFileExport(fileName, allStr);
	} catch (e) {
		$.messager.show({
			title: '错误',
			msg: '请用IE浏览器导出数据！',
			timeout: 1300,
			showType: 'slide',
			style: {
				right: '',
				bottom: ''
			}
		});
	}
}

function getTblData(curTbl, curTblContainer, rownumbers) {

	var outStr = "";
	if (curTbl != null) {
		var rowdata = curTbl.getRowData();
		var Lenr = 1;

		for (i = 0; i < Lenr; i++) {
			//var Lenc = curTbl.rows(i).cells.length;  
			var th;
			if (rownumbers == true) {
				th = curTblContainer.find('TH:not(:first-child)');
			} else {
				th = curTblContainer.find('TH');
			}
			th.each(function(index, element) {
				//alert($(element).text());  
				//取得每行的列数  
				var j = index + 1;
				var content = $(element).text();
				//alert(j + "|" + content);  
				outStr += content + "\t";
				//赋值  

			});
			outStr += "\r\n";
		}
		var tmp = "";
		for (i = 0; i < rowdata.length; i++) {
			var row = eval(rowdata[i]);
			for (each in row) {
				outStr += row[each] + "\t";
			}
			outStr += "\r\n";
		}


	} else {
		outStr = null;
		alert(inTbl + "不存在!");
	}
	return outStr;
}

function getExcelFileName(title) {
	var d = new Date();
	var curYear = d.getYear();
	var curMonth = "" + (d.getMonth() + 1);
	var curDate = "" + d.getDate();
	var curHour = "" + d.getHours();
	var curMinute = "" + d.getMinutes();
	var curSecond = "" + d.getSeconds();
	if (curMonth.length == 1) {
		curMonth = "0" + curMonth;
	}
	if (curDate.length == 1) {
		curDate = "0" + curDate;
	}
	if (curHour.length == 1) {
		curHour = "0" + curHour;
	}
	if (curMinute.length == 1) {
		curMinute = "0" + curMinute;
	}
	if (curSecond.length == 1) {
		curSecond = "0" + curSecond;
	}
	var fileName = title + "_" + curYear + curMonth + curDate + "_" + curHour + curMinute + curSecond + ".xls";
	//alert(fileName);   
	return fileName;
}

function doFileExport(inName, inStr) {
	var xlsWin = null;
	if (!!document.all("HideFrm")) {
		xlsWin = HideFrm;
	} else {
		var width = 6;
		var height = 4;
		var openPara = "left=" + (window.screen.width / 2 - width / 2) + ",top=" + (window.screen.height / 2 - height / 2) + ",scrollbars=no,width=" + width + ",height=" + height;
		xlsWin = window.open("", "_blank", openPara);
	}
	xlsWin.document.write(inStr);
	xlsWin.document.close();
	xlsWin.document.execCommand('Saveas', true, inName);
	xlsWin.close();
}